export default [
  {
    path: "/",
    redirect: "/login",
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/login.vue"),
    // 单页面多路由区域，在路由总定义多个组件加载
    /* components: {
      default: () => import("@/views/login.vue"),
      other1: () => import("@/views/other1.vue"),
      other2: () => import("@/views/other2.vue"),
    }, */
  },
  {
    path: "/layout",
    name: "loyout",
    component: () => import("@/views/layout.vue"),
    redirect: "/home",
    children: [
      {
        path: "/home",
        name: "home",
        meta: {
          title: "首页",
        },
        component: () => import("@/views/home.vue"),
      },
      {
        path: "/news",
        name: "news",
        component: () => import("@/views/news.vue"),
      },
      {
        path: "/manage",
        name: "manage",
        component: () => import("@/views/manage/index.vue"),
        redirect: "census",
        // 只要有children，在component导入的view种必须要有router-view出口
        children: [
          {
            // path: "/manage/census",
            path: "census", // 和上面等同，会将父级赋值到前面
            name: "census",
            component: () => import("@/views/manage/census.vue"),
          },
          {
            path: "/manage/order",
            name: "order",
            component: () => import("@/views/manage/order.vue"),
            // 路由独享守卫
            beforeEnter: (to, from, next) => {
              if (sessionStorage.getItem("sign")) {
                next();
              } else {
                alert("请完成打卡");
                next(false); // 中断进入，回到上一个router history
              }
            },
          },
        ],
      },
    ],
  },
];
